package com.example.demo.huawei;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/*
  字符串筛选排序
AbCdeFG
3
  输出
  5
 */
public class OD46 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String s = reader.readLine();
        int k = Integer.parseInt(reader.readLine());
        if (k < 0) return;

        //System.out.println(s);
        //        System.out.println(k);
        char[] chars = s.toCharArray();
        // 记录字符首次出现的位置
        Map<Character, Integer> posMap = new HashMap<>();
        int i = 0;
        for (char c : chars) {
            if (!posMap.containsKey(c)) {
                posMap.put(c, i);
            }
            i++;
        }
        //        System.out.println(posMap);
        // 找到该字符
        Arrays.sort(chars);
        //        System.out.println(Arrays.toString(chars));

        if (k > s.length()) {
            System.out.println(posMap.get(chars[chars.length - 1]));
        } else {
            System.out.println(posMap.get(chars[k - 1]));
        }
    }
}
